const request = require('./request')

const BASE_URL = '/finance/family'

/**
 * 获取该用户的家庭
 * @param {*} recordId 记录id 
 * @returns 
 */
function getMyFamily() {
  return request.get(BASE_URL + '/my')
}

/**
 * 解散家庭
 * @param {*} familyId 家庭id 
 * @returns 
 */
function dissolveFamily(familyId) {
  return request.post(BASE_URL + '/'+ familyId + '/dissolve')
}

/**
 * 退出家庭
 * @param {*} familyId 家庭id 
 * @returns 
 */
function quitFamily(familyId) {
  return request.post(BASE_URL + '/'+ familyId + '/quit')
}

/**
 * 生成邀请码
 * @param {*} familyId 家庭id
 * @returns 
 */
function generateInviteCode(familyId) {
  return request.post(BASE_URL + '/' + familyId + '/create/invite')
}

/**
 * 创建家庭
 * @param {string} familyName
 */
function createFamily(familyName) {
  return request.post(BASE_URL + '/create', { familyName });
}
/**
 * 加入家庭
 * @param {string} inviteCode
 */
function joinFamily(inviteCode) {
  return request.post(BASE_URL + '/join/create/invite', { inviteCode });
}

module.exports = {
  getMyFamily,
  dissolveFamily,
  quitFamily,
  generateInviteCode,
  createFamily,
  joinFamily
} 